home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 11 / Amoszine 11 (Disk 2 of 2).adf / Ben_Wyatt_Source.lha / Shaded_3D_Stars.AMOS / Shaded_3D_Stars.amosSourceCode
AMOS Source Code  |  2004-04-12  |  2KB  |  50 lines

  1. ' Shaded 3D Stars
  2. ' ~~~~~~~~~~~~~~~
  3. ' by Ben Wyatt, bwyatt@paston.co.uk
  4. '
  5. ' Slow when uncompiled, but much better when compiled with the pro compiler
  6. ' when using F Plot or Turbo Plot
  7.  
  8. ' Open a screen and do the boring old crap, that we all know how to do 
  9. Screen Open 0,320,256+(Ntsc*64),4,Lowres
  10. Screen Display 0,128,37,320,256+(Ntsc*64)
  11. Flash Off : Curs Off : Cls 0
  12. Palette $0,$555,$888,$EEE
  13. Double Buffer : Autoback 0
  14. Hide On 
  15.  
  16. ' Guess what this does... it calls the 3D stars procedure (150 stars)
  17. _3DSTARS[150]
  18.  
  19. Procedure _3DSTARS[STARS]
  20.  
  21.    ' Displays STARS amount of 3D stars
  22.    
  23.    ' Reserve some coords... (no Z coord for some reason ;-) ) 
  24.    Dim XSTAR(STARS),YSTAR(STARS)
  25.    SW=Screen Width*256 : SH=Screen Height*256
  26.    
  27.    ' Move these stars to random places to start with
  28.    For N=1 To STARS
  29.       XSTAR(N)=Rnd(SW)-SW/2 : YSTAR(N)=Rnd(SH)-SH/2
  30.    Next N
  31.    
  32.    Repeat 
  33.       For N=1 To STARS
  34.          X=Abs(XSTAR(N)) : Y=Abs(YSTAR(N))
  35.          If X>SW/2 or Y>SH/2
  36.             ' Off the side of the screen 
  37.             XSTAR(N)=Rnd(SW/2)-SW/4 : YSTAR(N)=Rnd(SH/2)-SH/4
  38.          Else 
  39.             ' Plot the star and add to it's x,y position 
  40.             ' Notice it uses powers of 2 (32, 256, 8192) to make it much 
  41.             ' faster with the pro compiler              This bit calculates the colour 
  42.             Plot(SW/2+XSTAR(N))/256,(SH/2+YSTAR(N))/256,Max(Min((X+Y)/8192,3),1)
  43.             Add XSTAR(N),XSTAR(N)/32 : Add YSTAR(N),YSTAR(N)/32
  44.          End If 
  45.       Next N
  46.       ' Swap screens, wait for a vbl and clear the screen :-)
  47.       Screen Swap : Wait Vbl : Cls 0
  48.    Until Key State(69) or Mouse Key>0
  49.    
  50. End Proc